package com.renjibo.sharkerwave.ui.activity;

import android.content.Intent;
import android.graphics.Color;
import android.support.design.widget.AppBarLayout;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.renjibo.sharkerwave.R;
import com.renjibo.sharkerwave.adapter.HomeTwoAdapter;
import com.renjibo.sharkerwave.models.Course;
import com.renjibo.sharkerwave.models.TopicDetail;
import com.renjibo.sharkerwave.network.SharkerParams;
import com.renjibo.sharkerwave.ui.view.StatusBarCompat;
import com.renjibo.sharkerwave.utils.ShowHideTop;

import org.xutils.common.Callback;
import org.xutils.x;

import java.util.ArrayList;
import java.util.List;


/**
 * 精选专辑详情页面
 */
public class HomeDetailsActivity extends BaseActivity {

    private RecyclerView home_details_recycler;
    private String object_id;
    private String session;
    private TextView home_details_text_title;
    private TextView home_details_text_title2;
    private TextView home_details_text_details;
    private ImageView home_Details_image_big;
    private AppBarLayout home_details_appBarLayout;
    private CollapsingToolbarLayout home_details_toolbar_layout;
    private Toolbar home_details_toolbar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_details);
        Intent intent = getIntent();
        object_id=intent.getStringExtra("object_id");
        initView();
        ShowHideTop.setWindow(this, true);

    }

    private void initView() {
        home_details_appBarLayout = (AppBarLayout) findViewById(R.id.home_Details_appBarLayout);
        home_details_toolbar_layout = (CollapsingToolbarLayout) findViewById(R.id.home_details_toolbar_layout);
//        home_details_toolbar_layout.setTitle("");
        home_details_toolbar = (Toolbar) findViewById(R.id.home_details_toolbar);
        setSupportActionBar(home_details_toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
//        getSupportActionBar().setDisplayShowTitleEnabled(false);
        StatusBarCompat.setStatusBarColorForCollapsingToolbar(this, home_details_appBarLayout, home_details_toolbar_layout, home_details_toolbar, Color.TRANSPARENT);

        findViewById(R.id.home_details_autoLinear_bottom).setScrollbarFadingEnabled(true);
        home_details_text_title = (TextView) findViewById(R.id.home_details_text_title);
        home_details_text_title2 = (TextView) findViewById(R.id.home_details_text_title2);
        home_details_text_details = (TextView) findViewById(R.id.home_details_text_details);
        home_Details_image_big = (ImageView) findViewById(R.id.home_Details_image_big);


        home_details_toolbar.setNavigationOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        home_details_recycler = (RecyclerView) findViewById(R.id.home_details_recycler);
//        toolbarLayout.setTitle("小明");
//        //通过CollapsingToolbarLayout修改字体颜色
//        toolbarLayout.setExpandedTitleColor(Color.WHITE);//设置还没收缩时状态下字体颜色
//        toolbarLayout.setCollapsedTitleTextColor(Color.GREEN);//设置收缩后Toolbar上字体的颜色


        home_details_recycler.setLayoutManager(new LinearLayoutManager(this));
        ArrayList<Course> courses = new ArrayList<>();
        courses.add(0,new Course());
        courses.add(1,new Course());
        courses.add(2,new Course());
        courses.add(3,new Course());
        detailTopic(session,object_id);

    }

//    // to change the title's font size of toolbar layout
//    private void setCollapsingToolbarLayoutTitle(String title) {
//        toolbarLayout.setExpandedTitleTextAppearance(R.style.ExpandedAppBar);
//        toolbarLayout.setCollapsedTitleTextAppearance(R.style.CollapsedAppBar);
//        toolbarLayout.setExpandedTitleTextAppearance(R.style.ExpandedAppBarPlus1);
//        toolbarLayout.setCollapsedTitleTextAppearance(R.style.CollapsedAppBarPlus1);
//    }
    /**
     * 网络请求  请求详细
     */
    void detailTopic(String session,String object_id) {
        SharkerParams params = new SharkerParams("detail_topic");
        params.addBodyParameter("object_id", object_id);
        x.http().post(params, new Callback.CommonCallback<TopicDetail>() {
            @Override
            public void onSuccess(TopicDetail result) {
                Log.d("zzz","re:"+result.toString());
                home_details_recycler.setAdapter(new HomeTwoAdapter(HomeDetailsActivity.this,result.course));
                home_details_text_title.setText(result.title+"");
                home_details_text_title2.setText(result.title2+"");
                home_details_text_details.setText(result.info+"");
                Glide.with(HomeDetailsActivity.this).load(result.topic_image+"").centerCrop().placeholder(R.drawable.bottom).error(R.drawable.bottom).into(home_Details_image_big);
            }

            @Override
            public void onError(Throwable ex, boolean isOnCallback) {

            }

            @Override
            public void onCancelled(CancelledException cex) {

            }

            @Override
            public void onFinished() {

            }
        });
    }

}
